/**
 * Created by PanJiaChen on 16/11/18.
 */

/**
 * 把请求回来的数据映射成tree组件数据
 * @param { { pid: string; id: string; name: string }[] } data
 * @param { string } currentId
 * @returns { { pid: string; id: string; name: string, children: any[] }[] }
 */
export function getTreeData(data, currentId = '0') {
  return data
    .filter(d => d.pid === currentId)
    .map(d => {
      // d.id: 当前id
      d.children = getTreeData(data, d.id)
      return d
    })
}
